﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ProjectEF6
{
    /// <summary>
    /// Interaction logic for Edituser.xaml
    /// </summary>
    public partial class EditReservation : Window
    {
        DB db = new DB();
        Panel p = new Panel();
        public EditReservation(int reservationId, DateTime start, DateTime end, int companyid, int locationid)
        {
            InitializeComponent();
            txtId.Text = reservationId.ToString();
            txtStart.Text = start.ToString();
            txtEnd.Text = end.ToString();
            txtCompanyId.Text = companyid.ToString();
            txtLocation.Text = locationid.ToString();
        }

        private void btnAccept_Click(object sender, RoutedEventArgs e)
        {   
            int insertId = Convert.ToInt32(txtId.Text);
            DateTime insertStart = Convert.ToDateTime(txtStart.Text);
            DateTime insertEnd = Convert.ToDateTime(txtEnd.Text);
            int insertCompanyId = Convert.ToInt32(txtCompanyId.Text);
            int insertLocationId = Convert.ToInt32(txtLocation.Text);
            
            if (p.checkDates(insertStart, insertEnd, insertLocationId, insertId) == true && p.checkContract(insertStart, insertEnd, insertCompanyId, insertId) == true)
            {
                if (db.editReservation(insertId, insertStart, insertEnd, insertCompanyId, insertLocationId))
                {
                    this.Close();
                }
                
            }
            
        }

    }
}
